/*
 * File:     wiideviceconnector.cpp
 * Authors:  Dominic Stalder, Thomas Bruederli
 *
 * Implementation of the device initialization thread class
 *
 * This file is part of the Qt-based cross-platform Wii device driver.
 *
 * Copyright (C) 2009-2010, Dominic Stalder & Thomas Bruederli
 * Licensed under the GNU Lesser General Public License (LGPL) as published
 * by the Free Software Foundation at http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * $Id: wiideviceconnector.cpp 2 2010-02-15 12:48:56Z roundcube $
 */

#include "wiideviceconnector.h"

/**
 * Main loop of the thread
 */
void WiiDeviceConnector::run()
{
	running = 1;

	wiiboard->start();
	
	// wait until wii board is connected
	while(running && !wiiboard->isConnected())
		usleep(50000);
	
	if (running)
		wiicontroller->start();
}

/**
 * Method to stop this thread
 */
void WiiDeviceConnector::stop()
{
	running = 0;
	
	if (wiiboard->isRunning())
	{
		wiiboard->stop();
		wiiboard->wait();
	}
	
	if (wiicontroller->isRunning())
	{
		wiicontroller->stop();
		wiicontroller->wait();
	}
}
